<?php
use PMA\libraries\Partition;
use PMA\libraries\StorageEngine;

?>
<form method="post"
      action="<?= $action; ?>"
      class="<?= ($action == 'tbl_create.php' ? 'create_table' : 'append_fields'); ?>_form ajax lock-page">
    <?= PMA_URL_getHiddenInputs($form_params); ?>
   <!-- happens when an index has been set on a column -->
   <!-- and a column is added to the table creation dialog -->
   <!-- This contains a JSON-encoded string -->
    <input type="hidden"
           name="primary_indexes"
           value="<?= (! empty($_REQUEST['primary_indexes'])) ?
                      htmlspecialchars($_REQUEST['primary_indexes'])
                      : '[]'
                  ?>">
    <input type="hidden"
           name="unique_indexes"
           value="<?= (! empty($_REQUEST['unique_indexes'])) ?
                      htmlspecialchars($_REQUEST['unique_indexes'])
                      : '[]'
                  ?>">
    <input type="hidden"
           name="indexes"
           value="<?= (! empty($_REQUEST['indexes'])) ?
                      htmlspecialchars($_REQUEST['indexes'])
                      : '[]'
                  ?>">
    <input type="hidden"
           name="fulltext_indexes"
           value="<?= (! empty($_REQUEST['fulltext_indexes'])) ?
                      htmlspecialchars($_REQUEST['fulltext_indexes'])
                      : '[]'
                  ?>">
    <input type="hidden"
           name="spatial_indexes"
           value="<?= (! empty($_REQUEST['spatial_indexes'])) ?
                      htmlspecialchars($_REQUEST['spatial_indexes'])
                      : '[]'
                  ?>">

    <?php if ($action == 'tbl_create.php'): ?>
        <div id="table_name_col_no_outer">
            <table id="table_name_col_no">
                <tr class="vmiddle floatleft">
                    <td><?= __('Table name'); ?>:&nbsp;
                    <input type="text"
                           name="table"
                           size="40"
                           maxlength="64"
                           value="<?= (isset($_REQUEST['table']) ? htmlspecialchars($_REQUEST['table']) : '') ?>"
                           class="textfield" autofocus required />
                    </td>
                    <td>
                        <?= __('Add'); ?>
                        <input type="number"
                               id="added_fields"
                               name="added_fields"
                               size="2"
                               value="1"
                               min="1"
                               onfocus="this.select()" />
                        <?= __('column(s)'); ?>
                        <input type="button"
                               name="submit_num_fields"
                               value="<?= __('Go'); ?>" />
                    </td>
                </tr>
            </table>
        </div>
    <?php endif; ?>
    <?php if (is_array($content_cells)): ?>
        <?= PMA\libraries\Template::get(
            'columns_definitions/table_fields_definitions'
        )->render(array(
            'is_backup' => $is_backup,
            'fields_meta' => $fields_meta,
            'mimework' => $mimework,
            'content_cells' => $content_cells
        )); ?>
    <?php endif; ?>
    <?php if ($action == 'tbl_create.php'): ?>
        <table>
            <tr class="vtop">
                <th>
                    <?= __('Table comments:'); ?>
                </th>
                <td width="25">&nbsp;</td>
                <th>
                    <?= __('Collation:'); ?>
                </th>
                <td width="25">&nbsp;</td>
                <th>
                    <?= __('Storage Engine:'); ?>
                    <?= PMA\libraries\Util::showMySQLDocu('Storage_engines'); ?>
                </th>
                <td width="25">&nbsp;</td>
                <th>
                    <?= __('Connection:'); ?>
                    <?= PMA\libraries\Util::showMySQLDocu('federated-create-connection'); ?>
                </th>
            </tr>
            <tr>
                <td>
                    <input type="text"
                           name="comment"
                           size="40"
                           maxlength="60"
                           value="<?= (isset($_REQUEST['comment']) ? htmlspecialchars($_REQUEST['comment']): ''); ?>"
                           class="textfield" />
                </td>
                <td width="25">&nbsp;</td>
                <td>
                    <?= PMA_generateCharsetDropdownBox(
                        PMA_CSDROPDOWN_COLLATION,
                        'tbl_collation',
                        null,
                        isset($_REQUEST['tbl_collation']) ? $_REQUEST['tbl_collation'] : null,
                        false
                    ); ?>
                </td>
                <td width="25">&nbsp;</td>
                <td>
                    <?= StorageEngine::getHtmlSelect(
                        'tbl_storage_engine',
                        null,
                        (isset($_REQUEST['tbl_storage_engine']) ? $_REQUEST['tbl_storage_engine'] : null)
                    ); ?>
                </td>
                <td width="25">&nbsp;</td>
                <td>
                    <input type="text"
                           name="connection"
                           size="40"
                           value="<?= (isset($_REQUEST['connection']) ? htmlspecialchars($_REQUEST['connection']) : ''); ?>"
                           placeholder="scheme://user_name[:password]@host_name[:port_num]/db_name/tbl_name"
                           class="textfield"
                           required="required" />
                </td>
            </tr>
            <?php if (Partition::havePartitioning()): ?>
                <tr class="vtop">
                    <th colspan="5">
                        <?= __('PARTITION definition:'); ?>
                        &nbsp;
                        <?= PMA\libraries\Util::showMySQLDocu('Partitioning'); ?>
                    </th>
                </tr>
                <tr>
                    <td colspan="5">
                        <?php include 'libraries/tbl_partition_definition.inc.php'; ?>
                    </td>
                </tr>
            <?php endif; ?>
        </table>
        <br />
    <?php endif; ?>
    <fieldset class="tblFooters">
        <input type="button"
               class="preview_sql"
               value="<?= __('Preview SQL') ?>" />
        <input type="submit"
               name="do_save_data"
               value="<?= __('Save'); ?>" />
    </fieldset>
    <div id="properties_message">
    </div>
</form>